# Makefile
# Para compilar:
# 	mpicc aquivo.c -o arquivo

# Para executar:
# 	mpirun -np <n> arquivo

# Para passar os hosts na execução:
# 	mpirun --hosts node01,node02,...,node0n -np <n> arquivo

# Para passar o arquivo de hosts na execução:
# 	mpirun --hostfile <arquivo de hosts> -np <n> arquivo

all: clean compile run

compile:
	@mpicc smooth_mpi.c -o smooth_mpi
	@gcc smooth_seq.c -o smooth_seq
	@gcc sp.c -o sp -lm

run:
	@# @mpirun -np 8 smooth_mpi < ./in/chrome.ppm > ./out/schrome.ppm
	@#@mpirun -np 4 smooth_mpi < ./in/chrome.ppm > schrome.ppm
	
	@./smooth_seq 3 tempo_seq.txt < ./in/chrome.ppm > smooth_seq_chrome.ppm
	@mpirun -np 4 smooth_mpi tempo_mpi.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 4 smooth_mpi tempo_mpi.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 4 smooth_mpi tempo_mpi.txt < ./in/chrome.ppm > ./out/schrome.ppm
	# @./sp tempo_seq.txt tempo_mpi.txt 4 speedupChrome
	#@mpirun -np 4 smooth_mpi < ./in/in.ppm 

runcluster:
	#sequencial
	@./smooth_seq 3 tempo_seq_chrome.txt < ./in/chrome.ppm > ./out/schrome_seq.ppm

	#paralelo
	@mpirun -f host_file -np 1 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 1 processos por nó
	@mpirun -f host_file -np 2 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 2 processos por nó
	@mpirun -f host_file -np 3 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 3 processos por nó
	@mpirun -f host_file -np 4 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 4 processos por nó
	@mpirun -f host_file -np 5 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 5 processos por nó
	@mpirun -f host_file -np 6 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 6 processos por nó	
	@mpirun -f host_file -np 7 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 7 processos por nó
	@mpirun -f host_file -np 8 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 8 processos por nó
	@mpirun -f host_file -np 9 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 9 processos por nó
	@mpirun -f host_file -np 10 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 10 processos por nó
	@mpirun -f host_file -np 11 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 11 processos por nó
	@mpirun -f host_file -np 12 ./smooth_mpi tempo_mpi_chrome.txt < ./in/chrome.ppm #Executa com 12 processos por nó
	#calcula o speedup:
	@./sp tempo_seq_chromelands.txt tempo_mpi_chrome.txt 12 speedup_chrome_cluster.txt

runtesteschrome:
	#sequencial
	@./smooth_seq 3 tempo_seq_chromelands.txt < ./in/chrome.ppm > ./out/schrome_seq.ppm

	#mpi
	@mpirun -np 1 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 1 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 1 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome1.txt 1 

	@mpirun -np 2 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 2 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 2 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	
	# @./sp tempo_seq_chromelands.txt tempo_mpichrome2.txt 2

	@mpirun -np 3 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 3 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 3 smooth_mpi tempo_mpichrome.txt < ./in/chrome.ppm > ./out/schrome.ppm
	
	# @./sp tempo_seq_chromelands.txt tempo_mpichrome3.txt 3

	@mpirun -np 4 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 4 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 4 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	
	# @./sp tempo_seq_chromelands.txt tempo_mpichrome4.txt 4

	@mpirun -np 5 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 5 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 5 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome5.txt 5

	@mpirun -np 6 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 6 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 6 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome6.txt 6

	@mpirun -np 7 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 7 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 7 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome7.txt 7

	@mpirun -np 8 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 8 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 8 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome8.txt 8

	@mpirun -np 9 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 9 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 9 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome9.txt 9

	@mpirun -np 10 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 10 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 10 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome0.txt 10

	@mpirun -np 11 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 11 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 11 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome1.txt 11

	@mpirun -np 12 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 12 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 12 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome2.txt 12

	@mpirun -np 13 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 13 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 13 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome3.txt 13

	@mpirun -np 14 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 14 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 14 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome4.txt 14

	@mpirun -np 15 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 15 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 15 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome5.txt 15

	@mpirun -np 16 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 16 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 16 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome6.txt 16

	@mpirun -np 17 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 17 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 17 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome17.txt 17

	@mpirun -np 18 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 18 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 18 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome8.txt 18

	@mpirun -np 19 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 19 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 19 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	# @./sp tempo_seq_chromelands.txt tempo_mpichrome19.txt 19

	@mpirun -np 20 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 20 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm
	@mpirun -np 20 smooth_mpi tempo_mpichrome.txt  < ./in/chrome.ppm > ./out/schrome.ppm

	@./sp tempo_seq_chromelands.txt tempo_mpichrome.txt 20 speedUpchrome.txt

upload:
	scp -P 22200 *.c *.h Makefile grupo08a@cluster.lasdpc.icmc.usp.br:/home/grupo08a/proj3
		
runcuda:
	@nvcc smooth_cuda.cu -o smooth_cuda
	@./smooth_cuda 0 < ./in/chrome.ppm > ./out/cudachrome.ppm
	
	
clean:
	@rm -f *.txt
	@rm -f teste
	@rm -f smooth_mpi

zip:
	@zip ./"backup/t4_"`date +"%d-%m-%Y_%H:%M"` ./Makefile ./*.c
